package com.itboye.eweilisten.util.widget;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;

import com.itboye.eweilisten.R;
import com.itboye.eweilisten.adapter.GirlGridAdapter;
import com.itboye.eweilisten.adapter.HeadGridAdapter;
import com.itboye.eweilisten.model.QuestionBean;
import com.itboye.eweilisten.util.popwindow.BaseDialogFragment;
import com.itboye.eweilisten.util.sputil.Const;
import com.itboye.eweilisten.util.sputil.SPUtils;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.ObjectAnimator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by itboye on 2017/3/10.
 */

public class HeadDialogs extends BaseDialogFragment {

    HeadGridAdapter oldAdapter;
    GirlGridAdapter gridAdapter;
    List<GoodBean> list = new ArrayList<GoodBean>();
    MyGridView guigeContainer, guigeContainernv;
    TextView okchongzhi;
    TextView tvdialogTitle;
    boolean ischat = true;
    int i;
    String one, two;

    QuestionBean bean;

    public HeadDialogs() {
    }
    @SuppressLint("ValidFragment")
    public HeadDialogs(QuestionBean bean) {
        this.bean = bean;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return LayoutInflater.from(getContext()).inflate(
                R.layout.head_gridbview, null);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);
        onDidlog();
        tvdialogTitle.setText("男");
    }

    public void onDidlog() {
        list.clear();
//        gridAdapter = new GirlGridAdapter(getContext(), bean);
//        guigeContainernv.setAdapter(gridAdapter);
//        oldAdapter = new HeadGridAdapter(getContext(), list);
//        guigeContainer.setAdapter(oldAdapter);

        okchongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                closeDialog();


            }
        });
    }

    public void onGriView(String text) {

        if (text.equals("one")) {
            guigeContainernv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    SPUtils.put(getActivity(), null,
                            Const.ONE, position);
                }
            });
        } else {
            guigeContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    SPUtils.put(getActivity(), null,
                            Const.ONE, position);
                }
            });
        }
    }

    /***
     * 关闭弹框
     */
    public void closeDialog() {

        View v = getView().findViewById(R.id.okchongzhi);
        ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationY",
                0, v.getHeight()).setDuration(300);
        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator arg0) {
            }

            @Override
            public void onAnimationRepeat(Animator arg0) {
            }

            @Override
            public void onAnimationEnd(Animator arg0) {
                dismiss();
            }

            @Override
            public void onAnimationCancel(Animator arg0) {
                dismiss();
            }
        });
        animator.start();
    }
}
